package com.example.tliaswebmanagement.controller;


import com.example.tliaswebmanagement.entity.PageResult;
import com.example.tliaswebmanagement.entity.Result;
import com.example.tliaswebmanagement.entity.Student;
import com.example.tliaswebmanagement.service.StudentService;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    private final StudentService studentService;
    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }

    //分页查询员工列表
    @GetMapping
    public Result findAll(@RequestParam(defaultValue = "1")Integer page,
                          @RequestParam(defaultValue = "10")Integer pageSize,
                          String name, Integer degree, Integer clazzId){
        log.info("分页查询员工列表，page={},pageSize={},name={},degree={},clazzId={}",page,pageSize,name,degree,clazzId);
        PageResult<Student> list = studentService.findAll(page,pageSize,name,degree,clazzId);
        return Result.success(list);
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Student student = studentService.findById(id);
        return Result.success(student);
    }
}
